home *** CD-ROM | disk | FTP | other *** search
/ NeXT Enterprise Objects Framework 1.1 / NeXT Enterprise Objects Framework 1.1.iso / NextDeveloper / Headers / foundation / NSValue.h < prev    next >
Encoding:
Text File  |  1995-01-31  |  3.3 KB  |  92 lines

  1. /*    NSValue.h
  2.     Copyright 1994 NeXT, Inc. All rights reserved.
  3.  
  4.     Use NSValues to put random C-types into collections.
  5.     Use NSNumbers to put numbers into collections.
  6.  
  7. */
  8. #import <foundation/NSObject.h>
  9. #import <foundation/NSString.h>
  10.  
  11. /* An abstract class for wrapping any C-type with an object. Sample use: To put an NSRange into an NSArray, you would [myArray insertObject:[NSValue value:&range withObjCType:@encode(NSRange)] atIndex:n]; to get it back out, [[myArray objectAtIndex:n] getValue:&range].
  12. */
  13. @interface NSValue : NSObject <NSCopying>
  14.  
  15. + (NSValue *)value:(const void *)value withObjCType:(const char *)type;    /* Creation method */
  16.  
  17. - (void)getValue:(void *)value;    /* Value copied from the object to caller's variable... */
  18. - (const char *)objCType;    /* Standard objC encoding string */
  19.  
  20. @end
  21.  
  22.  
  23. @interface NSValue (NSValueOtherTypes)
  24.  
  25. + (NSValue *)valueWithNonretainedObject:anObject;    /* Get objects into collections without retain */
  26. - nonretainedObjectValue;
  27.  
  28. + (NSValue *)valueWithPointer:(void *)pointer;    /* Get pointers into collections */
  29. - (void *)pointerValue;
  30.  
  31. @end
  32.  
  33.  
  34. /* An abstract class for wrapping C number types with an object. NSNumbers have the added feature that they can do type-coercion. The objCType method in an NSNumber can only be one of c, C, s, S, i, I, l, L, q, Q, f, or d. 
  35. */
  36. @interface NSNumber : NSValue
  37.  
  38. /* These methods return the number in the requested type. These methods will do type-coercion as defined by C. In certain cases the results may be undefined; for instance, trying to take the unsigned integer value of a negative number, or trying to get the short value of an float which is greater than the maximum short.
  39. */
  40. - (char)charValue;
  41. - (unsigned char)unsignedCharValue;
  42. - (short)shortValue;
  43. - (unsigned short)unsignedShortValue;
  44. - (int)intValue;
  45. - (unsigned int)unsignedIntValue;
  46. - (long)longValue;
  47. - (unsigned long)unsignedLongValue;
  48. - (long long)longLongValue;
  49. - (unsigned long long)unsignedLongLongValue;
  50. - (float)floatValue;
  51. - (double)doubleValue;
  52. - (BOOL)boolValue;
  53. - (NSString *)stringValue;
  54.  
  55. /* Compare the numbers exactly like C would.
  56. */
  57. - (NSComparisonResult)compare:(NSNumber *)otherNumber;
  58. @end
  59.  
  60. /* Creation methods for built-in subclasses of NSNumber
  61. */
  62. @interface NSNumber (NSNumberCreation)
  63. + (NSNumber *)numberWithChar:(char)value;
  64. + (NSNumber *)numberWithUnsignedChar:(unsigned char)value;
  65. + (NSNumber *)numberWithShort:(short)value;
  66. + (NSNumber *)numberWithUnsignedShort:(unsigned short)value;
  67. + (NSNumber *)numberWithInt:(int)value;
  68. + (NSNumber *)numberWithUnsignedInt:(unsigned int)value;
  69. + (NSNumber *)numberWithLong:(long)value;
  70. + (NSNumber *)numberWithUnsignedLong:(unsigned long)value;
  71. + (NSNumber *)numberWithLongLong:(long long)value;
  72. + (NSNumber *)numberWithUnsignedLongLong:(unsigned long long)value;
  73. + (NSNumber *)numberWithFloat:(float)value;
  74. + (NSNumber *)numberWithDouble:(double)value;
  75. + (NSNumber *)numberWithBool:(BOOL)value;
  76.  
  77. - initWithChar:(char)value;
  78. - initWithUnsignedChar:(unsigned char)value;
  79. - initWithShort:(short)value;
  80. - initWithUnsignedShort:(unsigned short)value;
  81. - initWithInt:(int)value;
  82. - initWithUnsignedInt:(unsigned int)value;
  83. - initWithLong:(long)value;
  84. - initWithUnsignedLong:(unsigned long)value;
  85. - initWithLongLong:(long long)value;
  86. - initWithUnsignedLongLong:(unsigned long long)value;
  87. - initWithFloat:(float)value;
  88. - initWithDouble:(double)value;
  89. - initWithBool:(BOOL)value;
  90. @end
  91.  
  92.